package cn.chenyumeng.blog.controller.blog;

import cn.chenyumeng.blog.dto.BlogDTO;
import cn.chenyumeng.blog.dto.CommonResponse;
import cn.chenyumeng.blog.dto.ResultCode;
import cn.chenyumeng.blog.service.blog.TagPageServer;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @program: blog->TagPageController
 * @description:
 * @author: cg
 * @create: 2020-08-10 18:31
 **/
@Validated
@RestController
@ResponseBody
@RequestMapping("/blog/tag")
public class TagPageController {

    @Autowired
    private TagPageServer tagPageServer;

    @GetMapping("/getBlogListByTagId")
    public CommonResponse getBlogListByTagId(@RequestParam(name = "page", defaultValue = "1") Integer page,
                                              @RequestParam(name = "size", defaultValue = "10") Integer size,
                                              @RequestParam(name = "tagId") Integer tagId) {
        PageInfo<BlogDTO> blogPageInfo = tagPageServer.getBlogListLimitByTagId(page, size, tagId);
        if (blogPageInfo == null) {
            return CommonResponse.build(ResultCode.PARAM_IS_INVALID);
        }
        return CommonResponse.ok(blogPageInfo);
    }

}
